<?php
include_once "BaseM.php";
 
class LogUserLoginoutM extends BaseM{
	
	public $table = "log_user_loginout";
	
	public function __construct() {
		parent::__construct ();
	}

	/**
	 * 新增
	 */
	public function insert($obj) {
		$sql = $this->genInserSQL($this->table, $obj);
		$result = @mysql_query($sql) or die ("sql : ".$sql.'\n'.mysql_error ());
		return $result;
	}

	/**
	 *取得全部
	 */
	public function queryTable($orderData, $startPage, $pageRow, $searchStr) {
		$whereStr = " 1 = 1 $searchStr ";
		
		$countSql = "select count(*) as count from $this->table where $whereStr ";
		
		$resultSql = "
			select 
				user_account, ip, type, date_modify, is_login,
				case type when 1 then '登入'
					when 2 then '登出'
				end type2,
				case is_login when 1 then '成功'
				              when 0 then '失敗'
				end is_login2
			from $this->table
			where $whereStr
			order by $orderData 
			limit $startPage, $pageRow ";
		
		return array( "count" =>  $this->querySQL($countSql, true)->count, "result" => $this->querySQL($resultSql) );
	}
	
	public function queryArea(){
		$resultSql = " select action_area from $this->table group by action_area ";
		return $result = $this->querySQL($resultSql);
	}

}

?>